package com.inossem.warehousestorage_inossem.adapter.allocation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.bean.allocation.AllocationOutStorageBaseInfoBean;

import java.util.List;

/**
 * 调拨出库 选择库存地点
 *
 * @author 詹建宇
 * @time on 2018/3/29 10:36
 * @email jianyu.zhan@inossem.com
 */
public class AllocationCreatDocumentFtyAdapter extends BaseAdapter {

    private Context context;
    private List<AllocationOutStorageBaseInfoBean.BaseInfoBodyBean.FtyListBean.LocationAryBean> list;
    private InventoryAddressListAdapterListener mInventoryAddressListAdapterListener;

    public AllocationCreatDocumentFtyAdapter(Context context, List<AllocationOutStorageBaseInfoBean.BaseInfoBodyBean.FtyListBean.LocationAryBean> list, InventoryAddressListAdapterListener mInventoryAddressListAdapterListener) {
        this.context = context;
        this.list = list;
        this.mInventoryAddressListAdapterListener = mInventoryAddressListAdapterListener;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.view_in_storage_select, null);
            holder = new ViewHolder();
            holder.text = (TextView) view.findViewById(R.id.text);
            holder.value = (TextView) view.findViewById(R.id.value);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        initData(context, holder, view, list.get(i));
        return view;
    }

    private void initData(Context context, ViewHolder viewHolder, View view, AllocationOutStorageBaseInfoBean.BaseInfoBodyBean.FtyListBean.LocationAryBean bean) {
        viewHolder.text.setText(bean.getLoc_code() + " - " + bean.getLoc_name());
        viewHolder.value.setText(bean.getLoc_id());
        view.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                mInventoryAddressListAdapterListener.onSelect(bean.getLoc_id(), bean.getLoc_code(), bean.getLoc_name());
            }
        });
    }

    private class ViewHolder {
        private TextView text, value;
    }


    public static abstract class InventoryAddressListAdapterListener {
        public abstract void onSelect(String id, String code, String name);
    }
}
